<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<include file="Public:base" />
<script type="text/javascript">
$(document).ready(function() {
	$("select[id='flag']").val('{$data.flag}');	
	var params = {
			fileInput : $("#fileImage").get(0),
			//dragDrop : $("#fileDragArea").get(0),
			upButton : $("#fileSubmit").get(0),
			url : $("#uploadForm").attr("action"),
			filter : function(files) {
				var arrFiles = [];
				for ( var i = 0, file; file = files[i]; i++) {
					if (file.type.indexOf("image") == 0) {
						if (file.size >= 512*1000) {
							alert('您这张"' + file.name
									+ '"图片大小过大，应小于500K');
						} else {
							arrFiles.push(file);
						}
					} else {
						alert('文件"' + file.name + '"不是图片。');
					}
				}
				return arrFiles;
			},
			onSelect : function(files) {
				var html = '', i = 0;
				$("#preview").html(
						'<div class="upload_loading"></div>');
				var funAppendImage = function() {
					file = files[i];
					if (file) {
						var reader = new FileReader()
						reader.onload = function(e) {
							html = html
									+ '<div id="uploadList_'+ i +'" class="upload_append_list"><p><strong>'
									+ file.name
									+ '</strong>'
									+ '<a href="javascript:" class="upload_delete" title="删除" data-index="'+ i +'">删除</a><br />'
									+ '<img id="uploadImage_' + i + '" src="' + e.target.result + '" class="upload_image" /></p>'
									+ '<span id="uploadProgress_' + i + '" class="upload_progress"></span>'
									+ '</div>';
							i++;
							funAppendImage();
						}
						reader.readAsDataURL(file);
					} else {
						$("#preview").html(html);
						if (html) {
							//删除方法
							$(".upload_delete")
									.click(
											function() {
												ZXXFILE
														.funDeleteFile(files[parseInt($(
																this)
																.attr(
																		"data-index"))]);
												return false;
											});
							//提交按钮显示
							$("#fileSubmit").show();
						} else {
							//提交按钮隐藏
							$("#fileSubmit").hide();
						}
					}
				};
				funAppendImage();
			},
			onDelete : function(file) {
				$("#uploadList_" + file.index).fadeOut();
			},
			
		};
		ZXXFILE = $.extend(ZXXFILE, params);
		ZXXFILE.init();


	
		$("#pushform").validate({
			
			errorPlacement: function (error, element) {
	            error.appendTo(element.parent().find('label'));
	            element.parent().addClass("has-error");
	        },
	        //获取焦点时不验证 
	        focusInvalid: false,   
	        onkeyup: false ,
			rules : {
				'title' : {
					required : true,
				},
				'flag' : {
					required : true
				},
				'fileselect' : {
					required : false
				},
				'url' : {
					required : true
				},
				'orderby' : {
					required : true,
					range:[1,99]
				}
			},
			messages : {
				'title' : {
					required : "请输入标题 "
				},
				'flag' : {
					required : "请填写标示 "
				},
				'fileselect' : {
					required : "请选择图片"
				},
				'url' : {
					required : "请输入链接地址"
				},
				'orderby' : {
					required : "请填写排序值",
					range:"请输入1~99的整数"
				}
			}
		});
	
});

</script>
</head>
<body>
<include file="Public:header" />

<div class="home-index">
	
    <div class="col-xs-12">
	<h2>编辑推送</h2>

		<div class="edit-user">
		<form id="pushform" role="form" method="post" action="__URL__/update"
			enctype="multipart/form-data">
		
		<div class="form-group"><label>推送标题</label> <input type="text" value="{$data.title}"
			name="title" class="form-control" placeholder="请输入标题"></div>
		<div class="form-group"><label>推送位置</label> 
			<html:select id='flag' name='flag' style="form-control" options='flaglist' first='请选择推送位置' /></div>
		</div>
		<div class="form-group"><label>推送图片</label> <input type="file"
			id="fileImage" name="fileselect" placeholder="请点击上传">
		</div>
			<div id="preview" class="upload_preview">
			 <div class="upload_append_list" >
			 	<p>
					<img src="__ROOT__{$data.img}" class="upload_image" />
				</p>
			 </div>
				
			</div>
		
		<div class="form-group"><label>推送链接</label> <input type="text" value="{$data.url}"
			name="url" class="form-control" placeholder="请输入链接地址"></div>
		<div class="form-group"><label>排序</label> <input type="text" value="{$data.orderby}"
			name="orderby" class="form-control" value="99" placeholder="默认99"></div>
		<input type="hidden" name="id"  value='{$data.id}' >	
		<button type="submit" class="btn btn-primary">提交</button>
		</form>

	</div>

	</div>
	
	
</div>

</body>
</html>